/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Service;

import Util.TranslatorUtils;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import th.co.tac.happy.ejb.sos.data.SosRequest;
import th.co.tac.happy.ejb.sos.data.SosResponse;
import th.co.tac.happy.ejb.sos.itf.SosBeanRemote;

/**
 *
 * @author Peat
 */
public class SOSService extends BaseService {

    public SosResponse canUseSOS(HttpServletRequest request) throws NamingException {

        this.readyEJB(null);

        if (!cache.containsKey("SosResponse")) {
            SosRequest req = new SosRequest();
            req.setLang(TranslatorUtils.getBackendLang(request));
            // except format 08xxxxxxx
            req.setSubrNumb((String) request.getSession().getAttribute("subrnumb"));

            SosBeanRemote bean = (SosBeanRemote) ic.lookup("JNDISosBean");
            SosResponse resp = bean.canUseSos(req);

            cache.put("SosResponse", resp);
        }
        return (SosResponse) cache.get("SosResponse");
    }

}
